package com.example.controller;

import com.example.common.result.Result;
import com.example.entity.dto.DeleteEmployeeDto;
import com.example.entity.dto.EmployeeDto;
import com.example.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通用接口
 */

@RestController
@RequestMapping("/employee")
@Api(tags = "员工接口")
@Slf4j
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @PostMapping("/Add")
    @ApiOperation("新增员工")
    public Result AddEmployee(@RequestBody EmployeeDto employeeDto){
        //创建日志对象
        log.info("新建项目信息：{}",employeeDto);
        employeeService.AddEmployee(employeeDto);
        return Result.success(employeeDto);
    }

    @PostMapping("/Delete")
    @ApiOperation("删除员工")
    public Result DeteleEmployee(@RequestParam Integer Id){
        //创建日志对象
        log.info("删除信息：{}",Id);
        employeeService.DeleteEmployee(Id);
        return Result.success(Id);
    }
    @PostMapping("/get")
    @ApiOperation("获取员工信息")
    public Result<List<EmployeeDto>> getEmployee(){
        //创建日志对象
        log.info("获取信息");
        List<EmployeeDto> list = employeeService.getEmployee();
        return Result.success(list);
    }
    @PostMapping("/update")
    @ApiOperation("修改员工信息")
    public Result updateEmployee(@RequestBody EmployeeDto employeeDto){
        //创建日志对象
        log.info("修改信息{}",employeeDto);
        employeeService.updateEmployee(employeeDto);
        return Result.success();
    }
}
